#include "unabto/unabto_env_base.h"
#include "unabto_crypto_test.h"
#include "unabto/unabto_crypto.h"


bool test_nabto_crypto_create_key_material() {
    bool result;
    uint8_t nonce[] = {
        0xad,    0x51,    0xba,    0xeb,    0x32,    0xcd,    0x8b,    0x7b,
        0xbe,    0x92,    0xea,    0xb4,    0x7b,    0xb2,    0xc2,    0x22,
        0x4b,    0xd6,    0xec,    0x9e,    0x1c,    0xa3,    0x3a,    0x0b,
        0x3d,    0x19,    0xe0,    0xaa,    0x8f,    0x8f,    0x64,    0xb3,
        0x00,    0x01,    0x02,    0x03,    0x04,    0x05,    0x06,    0x07,
        0x08,    0x09,    0x0a,    0x0b,    0x0c,    0x0d,    0x0e,    0x0f,
        0x10,    0x11,    0x12,    0x13,    0x14,    0x15,    0x16,    0x17,
        0x18,    0x19,    0x1a,    0x1b,    0x1c,    0x1d,    0x1e,    0x1f };

    uint8_t seed[] = {
        0x59,    0x81,    0x97,    0xad,    0xd9,    0x70,    0x6e,    0xb0,
        0x69,    0x9a,    0x5a,    0x5a,    0xbc,    0x32,    0x36,    0xd4,
        0x02,    0xbf,    0xf1,    0x5f,    0xa2,    0x11,    0x46,    0x7f,
        0x0e,    0x76,    0x95,    0x92,    0xc7,    0x9e,    0x1c,    0x6f,
        0x00,    0x01,    0x02,    0x03,    0x04,    0x05,    0x06,    0x07,
        0x08,    0x09,    0x0a,    0x0b,    0x0c,    0x0d,    0x0e,    0x0f,
        0x10,    0x11,    0x12,    0x13,    0x14,    0x15,    0x16,    0x17,
        0x18,    0x19,    0x1a,    0x1b,    0x1c,    0x1d,    0x1e,    0x1f };

    uint8_t keyDataResult[] = {
        0xc6,    0xf3,    0x14,    0xc9,    0xb5,    0x05,    0xdb,    0x88,
        0x7b,    0x94,    0x02,    0x50,    0xd9,    0xcc,    0xfb,    0x44,
        0xd1,    0xd2,    0x19,    0x16,    0x82,    0x1b,    0x71,    0x3e,
        0x93,    0xdc,    0x45,    0xc8,    0xdf,    0x66,    0x9b,    0x67,
        0x4b,    0x23,    0x5d,    0x43,    0x1c,    0xb7,    0x1d,    0x41,
        0x5a,    0x6b,    0x17,    0xdc,    0x6d,    0x51,    0x15,    0x1b,
        0x63,    0x3e,    0x36,    0x7e,    0x10,    0x18,    0xa5,    0x82,
        0x4d,    0x84,    0x70,    0x03,    0xf8,    0x2f,    0x34,    0x1f,
        0xd9,    0xc5,    0xf6,    0x39,    0x90,    0x52,    0xb1,    0x1c,
        0x65,    0xad,    0x13,    0x35,    0x93,    0xbc,    0x8a,    0x38,
        0xf8,    0xe5,    0x45,    0x12,    0x0b,    0x30,    0x7e,    0x19,
        0xa7,    0x30,    0x75,    0x81,    0x1c,    0x4f,    0xf8,    0xcb };

    
    uint8_t keyData[96];
    
    unabto_buffer nonces[1];
    unabto_buffer seeds[1];

    unabto_buffer_init(nonces, nonce, 64);
    unabto_buffer_init(seeds, seed, 64);

    nabto_crypto_create_key_material(nonces, 1, seeds, 1, keyData, 96);

    result = (memcmp(keyData, keyDataResult, 96) == 0);
    
    return result;
}
